package servlet.image;

import bean.Result;
import biz.BizException;
import biz.ImageBiz;
import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "AddImageServlet", value = "/AddImageServlet.s")
public class AddImageServlet extends HttpServlet {
    private ImageBiz biz = new ImageBiz();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        final String image = request.getParameter("image");
        final String proid = request.getParameter("proid");
        System.out.println(proid);
        Result result ;
            try {
                biz.addImage(proid,image);
                result = new Result(1,"图片添加成功!",null);
            } catch (BizException e) {
                e.printStackTrace();
                result = new Result(0,e.getMessage(),null);
            }
        final String json = new Gson().toJson(result);
        response.getWriter().append(json);
    }
}
